package com.bicon.botu.medical.api

import com.bicon.botu.core.base.common.controller.BaseController
import com.bicon.botu.core.base.common.entity.BaseResult
import com.bicon.botu.core.base.common.utils.StringUtils
import com.bicon.botu.core.base.validate.BeanFieldValidator
import com.bicon.botu.medical.param.EntryHealthParam
import com.bicon.botu.medical.service.IHealthInfoService
import com.bicon.botu.medical.service.IUserHealthDataService
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*


/**
 * 健康数据 -- 控制类
 *
 * @author 刘小鹏
 * @date 2018/07/17
 */
@RestController
@RequestMapping("/api/health")
open class MedicalApi : BaseController() {


    @Autowired
    open lateinit var healthService: IUserHealthDataService
    @Autowired
    open lateinit var healthInfoService: IHealthInfoService


    @ApiOperation(value = "保存用户体征数据", notes = "保存用户体征数据")
    @ApiImplicitParam(name = "entryHealthParam", value = "保存参数", required = true, dataType = "EntryHealthParam", paramType = "body")
    @PostMapping("/save-health-data")
    fun entryHealthData(@RequestBody entryHealthParam: EntryHealthParam): BaseResult<*> {
        BeanFieldValidator.getInstance().validate(entryHealthParam)
        if (StringUtils.isEmpty(entryHealthParam.userId)) {
            return sendResult400()
        }
        val saveHealthData = healthService.saveHealthData(entryHealthParam)
        return sendResult200(saveHealthData)
    }

    @ApiOperation(value = "获取健康资讯类别", notes = "获取健康资讯类别")
    @ApiImplicitParam(name = "birthday", value = "出生日期", required = true, dataType = "String", paramType = "query")
    @GetMapping("get-health-info")
    fun getHealthInfo(@RequestParam("birthday") birthday: String): BaseResult<*> {
        if (StringUtils.isBlank(birthday)) {
            return sendResult400()
        }
        return sendResult200(healthInfoService.getHealthInformationCategoryByAgeRange(birthday))
    }
}